import { Utils } from 'kryfe-lib';
import * as actionTypes from '../consts/actionTypes';
import API from '../api';

const { customShowLoading, customTimestampMeta } = Utils.customActionUtil;

export function syncAction(data) {
  return {
    type: actionTypes.SYNC_ACTION,
    payload: data
  };
}

export function asyncPromiseAction() {
  return {
    type: actionTypes.ASYNC_ACTION,
    payload: API.getData()
  };
}

export function asyncCustomAction() {
  return (dispatch) => {
    dispatch(customShowLoading(actionTypes.ASYNC_CUSTOM_ACTION));
    
    return dispatch({
      type: actionTypes.ASYNC_CUSTOM_ACTION,
      payload: API.getData(),
      meta: customTimestampMeta({
        handlers: {
          success: () => {
          },
          failed: () => {
          },
          finally: () => {
          }
        }
      }),
    });
  };
}
